 //定义依赖和插件
 var gulp = require('gulp'),
     connect = require('gulp-connect'),
     uglify = require('gulp-uglify'),
     sass = require('gulp-sass'),
     mincss = require('gulp-minify-css'),
     auto = require('gulp-autoprefixer'),
     imagemin = require('gulp-imagemin');
 //设置文件路径
 var jsSrc = 'src/js/*.js';
 var jsDist = 'dist/js';
 var htmlSrc = 'src/*.html';
 var htmlDist = 'dist';
 var sassSrc = 'src/sass/*.scss';
 var sassDist = 'dist/sass';
 var imgSrc = 'src/img/*.{png,jpg,gif,ico}';
 var imgDist = 'dist/img';
 var pluginSrc = 'src/plugin/**/*.{js,css}';
 var pluginDist = 'dist/plugin';
 //复制插件
  gulp.task('plugin', function() {
     gulp.src(pluginSrc)
         .pipe(gulp.dest(pluginDist))
         .pipe(connect.reload());

 });
 //定义名为js的任务
 gulp.task('js', function() {
     gulp.src(jsSrc)
         .pipe(gulp.dest(jsDist))
         //.pipe(uglify())
         .pipe(gulp.dest(jsDist))
         .pipe(connect.reload());

 });
 //定义html任务
 gulp.task('html', function() {
     gulp.src(htmlSrc)
         .pipe(gulp.dest(htmlDist))
         .pipe(connect.reload());
 });
 //定义sass任务
 gulp.task('sass', function() {
     gulp.src(sassSrc)
         .pipe(sass())
         .pipe(mincss())
         .pipe(auto())
         .pipe(gulp.dest(sassDist))
         .pipe(connect.reload());
 });

 //压缩图片
 gulp.task('imagemin', function() {
     gulp.src('src/img/*.{png,jpg,gif,ico}')
         .pipe(imagemin())
         .pipe(gulp.dest(imgDist))
         .pipe(connect.reload());
 });
 //开启本地服务器及代理
 var proxy = require('http-proxy-middleware');
 gulp.task('connect', function() {
     connect.server({
         livereload: true,
         middleware: function(connect, opt) {
             return [
                 proxy('/base', {
                     //target: 'https://www.rongxwy.com',
                     target: 'http://dvp.rongxwy.com',
                     changeOrigin: true
                 })
             ];
         }
     });
 });
 //定义看守任务
 gulp.task('watch', function() {
     gulp.watch('src/*.html', ['html']);
     gulp.watch('src/js/*.js', ['js']);
     gulp.watch('src/sass/*.scss', ['sass']);
     gulp.watch('src/img/*.{png,jpg,gif,ico}', ['imagemin']);
 });
 //定义默认任务
 gulp.task('default', ['js', 'html', 'watch', 'connect', 'sass','imagemin','plugin']);